{extend name="admin/public/base" /}

{block name="content"}
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    栏目列表
    <small></small>
  </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">内容</a></li>
    <li class="active">栏目列表</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="box box-solid">
        <div class="box-header with-border">
            <a href="{:Url('admin/category/create')}" class="btn btn-default btn-flat"><i class="fa fa-plus-square"></i> 创建栏目</a>
            <a href="javascript::void(0)" onclick="reorder()" class="btn btn-default btn-flat"><i class="fa fa-sort-amount-desc"></i> 排序</a>
        </div>
        <div class="box-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>#ID</th>
                            <th>名称</th>
                            <th>别名</th>
                            <th>模式<i class="fa fa-fw fa-question-circle" data-toggle="tooltip" data-placement="top" title="列表模式下可以发布内容"></i></th>
                            <th>绑定模型</th>
                            <th>排序<i class="fa fa-fw fa-question-circle" data-toggle="tooltip" data-placement="top" title="数值越大排名越靠前"></i></th>
                            <th>显示</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <form id="category" method="post">
                        {volist name="data" id="vo"}
                        <tr id = "t_{$vo.id}">
                            <td>{$vo.id}</td>
                            <td>{neq name="vo.level" value="1"}<span style="color:#ccc;">{$vo.html}|----</span>{/neq}{$vo.title}</td>
                            <td>{$vo.alias}</td>
                            <td>{eq name="vo.type" value="0"}列表模式{else/}封面模式{/eq}</td>
                            <td>{$vo.module_name}</td>
                            <td>
                                <input name="ids[]" type="hidden" value="{$vo.id}">
                                <input class="form-control input-sm" style="width:50px;height:20px;" name="reorder[]" type="text" value="{$vo.reorder}">
                            </td>
                            <td>{eq name="vo.status" value="1"}
                                <small class="label bg-light-gray"><i class="fa fa-times"></i></small>
                                {else/}
                                <small class="label bg-light-blue"><i class="fa fa-check"></i></small>
                                {/eq}
                            </td>
                            <td>
                                <div class="btn-group">
                                    <a href="{:Url('admin/category/edit',['id'=>$vo.id])}" class="btn btn-default btn-xs"><i class="fa fa-edit"></i></a>
                                    <a onClick="deleteOne({$vo.id})" class="btn btn-default btn-xs"><i class="fa fa-trash-o"></i></a>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                        </form>
                    </tbody>
                </table>
            </div>

        </div>
    </div>

</section>
<!-- /.content -->
{/block}


{block name="js"}
<script>
    function reorder(){
        $.ajax({
            url:"{:Url('admin/category/reorder')}",
            data:$("#category").serialize(),
            type:'post',
            dataType:'json',
            success: function(xhr){
                if(xhr.code == 200){
                    swal(xhr.msg, "", "success");
                }else{
                    swal(xhr.msg, "", "error");
                }
            }
        })
    }

    function deleteOne(id){
            swal({
                title: "确定删除这条信息吗?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        url:"{:Url('admin/category/remove')}",
                        data:{'id':id},
                        type:'post',
                        dataType:'json',
                        success: function(xhr){
                            if(xhr.code == 200){
                                swal(xhr.msg, "", "success");
                                $("#t_"+id).remove();
                            }else{
                                swal(xhr.msg, "", "error");
                            }
                        }
                    })
                } else {
                    swal("取消操作", "", "error");
                }
            });
    }
</script>
{/block}
